package com.awesomeproject;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

import androidx.annotation.NonNull;

import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;

public class AppManageModule extends ReactContextBaseJavaModule {
    private final ReactApplicationContext context;

    AppManageModule(ReactApplicationContext context) {
        super(context);
        this.context=context;
    }
    @NonNull
    @Override
    public String getName() {
        return "AppModule";
    }
    @ReactMethod
    public void getVersion(Promise promise){
        PackageManager manager = this.context.getPackageManager();
        int code = 0;
        String name= "";
        try {
            PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0);
            code = info.versionCode;
            name=info.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        promise.resolve(name);
    }
}
